package juc;

import java.util.concurrent.*;

/**
 * @author hck
 */
public class TestThreadPool {
    private final String str;

    public TestThreadPool() {
        str = "qqq";
    }

//    {
//        str = "hhh";
//    }

    public static void main(String[] args) {
        ThreadPoolExecutor executorService = new ThreadPoolExecutor(5, 8,
                100, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2));

//        ThreadPoolExecutor syncExecuteService = new ThreadPoolExecutor(5, 10,
//                100, TimeUnit.SECONDS,
//                new SynchronousQueue<>());

        for (int i = 0; i < 12; i++) {
            int finalI = i;
            executorService.submit(() -> {
                System.out.println("this is new task:" + finalI);
                synchronized (Thread.currentThread()) {
                    try {
                        Thread.currentThread().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("task [" + finalI + "] end");
            });
            System.out.println("core:" + executorService.getCorePoolSize());
            System.out.println("pool:" + executorService.getPoolSize());
            System.out.println("-----------------------------------");
        }
    }
}
